home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Macintosh / MacShell.0.54b.sit / MacShell.0.54b / MacShell.0.54b.rsrc / help_14929_macshell < prev    next >
Text File  |  1996-01-21  |  19KB  |  311 lines

  1. MACSHELL - GENERAL INFORMATION 
  2.  
  3. MacShell is a Unix-like command line interface for the Macintosh.  It performs a limited imitation of the Unix C shell, and contains abbreviated versions of a set of Unix style file management, file finding, content searching, and miscellaneous utilities.  It also does a few Macintosh-specific functions, is scriptable, can execute compiled external code segments, and has a no-frills text editor built-in.
  4.  
  5. MacShell is free, courtesy of its author.  It may not be sold in any form.
  6.  
  7. THE SHELL
  8.  
  9. The "Shell" component of the program has the following capabilities:
  10. -Executes a set of built-in utilities.
  11. -Executes code resources from external resource files.
  12. -Performs file name substitution. (known to some as "globbing")
  13. -Handles pipes.
  14. -Performs redirection of standard I/O to and from files using the operators ">" ">>" and "<".
  15. -Performs backquote substitution.
  16. -Manages shell variables.
  17. -Uses shell aliases.
  18. -Runs scripts.
  19. -Manages command history.
  20.  
  21. Among the many "shell" functions which MacShell does not support are the following:
  22. -Flow control operators
  23. -Launching of other applications
  24.  
  25. BUILT-IN UTILITIES
  26.  
  27. This version performs approximations of the Unix utilities in the following list.
  28.  
  29. Note:  to get more help with any command, type:
  30.                 man commandname
  31.  
  32. command    description
  33. -------    -----------
  34.   man      get help
  35.   cd       change directory
  36.   pwd      print working directory
  37.   ls       show the contents of a directory
  38.   cat      concatenate
  39.   head     copy the beginning of the input to the output
  40.   tail     copy the end of the input to the output
  41.   cp       copy files
  42.   mv       move or rename files
  43.   rm       remove files
  44.   mkdir    make directory
  45.   grep     content search utility
  46.   egrep    content search using regular expressions
  47.   find     find a file 
  48.   more     view a file
  49.  
  50. Additionally MacShell approximates some utilities which are built in to the Unix C-shell:
  51.  
  52.   set      set a shell variable
  53.   unset    clear, or unset a shell variable
  54.   alias    define a shell alias
  55.   unalias  undefine a shell alias
  56.   echo     report command line arguments on the output.
  57.   source   execute a file as a script
  58.   rehash   rebuild internal tables for 'path' and 'manpath'
  59.   which    expand command name using the 'path' variable 
  60.   history  display the current command history list
  61.   exit     quit MacShell
  62.  
  63. Finally, MacShell has a few special non Unix-like functions:
  64.  
  65.   mem       show heap statistics
  66.   free      show free heap space
  67.   compact   compact heap and report largest contiguous block
  68.   seg       filter to segment long lines into shorter lines
  69.   xn        filter out null characters from a stream
  70.   chtype    change a Macintosh file type signature
  71.   chcreator change a Macintosh file creator signature
  72.   bintohex  convert input to hexidecimal notation
  73.  
  74. For information about MacShell version history, invoke:
  75.   man version
  76.  
  77. DETAILS OF SHELL FUNCTIONS
  78.  
  79. The following "shell" functionality is supported by MacShell:
  80.  
  81. FILE NAME SUBSTITUTION
  82.  
  83. If MacShell finds the asterisk (*) in a command argument, it will attempt to substitute any string of characters (including the null string) in place of the asterisk to form one or more valid file names.  This name (or these names) will be substituted into the command string prior to the execution of the command.  Correct case must be observed when this mechanism is used. (Otherwise the Macintosh is case-insensitive.) 
  84.  
  85. An asterisk may be hidden from MacShell by surrounding the argument that contains it in either double ("") or single ('') quotes.  The argument will then be passed on to its command unaltered.
  86.  
  87. PIPE HANDLING
  88.  
  89. MacShell allows the output of one of its commands to be directed to the input of another by means of a pipe.  The pipe character (|) is used to separate the two commands.  (Note that MacShell's internal implementation of the pipe is quite different from the Unix implementation, even though they behave very similiarly)
  90.  
  91. REDIRECTION OF COMMAND INPUT AND OUTPUT TO AND FROM FILES
  92.  
  93. MacShell supports the use of I/O redirection operators "<", ">>" and ">".   A filename which follows the input redirection symbol (<) on the command line will be opened and its contents will be used as input for the command.  A filename which follows the output redirection operator (>) will be created if it does not exist, and the output of the command will be written to it.  If the file does exist, an error results.  A filename which follows the append operator (>>) will be created if it does not exist (or opened if it does exist), and the output of the command will be appended to it.
  94.  
  95. SHELL VARIABLES
  96.  
  97. MacShell is capable of managing shell variables.  Shell variables are set and cleared with "set" and "unset." (See separate manual entries for set and unset).  Set is also useful for displaying a list of currently defined variables and their values.  
  98.  
  99. Once a shell variable is defined its value may be used by the variable substitution mechanism to form part of a command line.  Variable substitution is triggered by a '$' immediately preceeding the variable name. Variable substitution takes place before file name substitution.  The entire variable (including the index, if used) may be surrounded by curly braces '{}' to avoid ambiguity if the name does not form a separate argument.
  100.  
  101. It's possible to hide a '$' from the variable substitution mechanism by enclosing its argument in single quotes.
  102.  
  103. A shell variable may take a value of zero or more words.  If the value consists of more than one word, the individual words may be selected by means of an index value in square brackets immediately following the variable name.  The index value itself may be a shell variable since the variable substitution mechanism will evaluate index values first. Index values begin at 1.  Supplying an index value of zero generates an error.
  104.  
  105. Special designators "$#" and "$?" can be used immediatly preceeding a shell variable name to cause the substitution mechanism to insert other information about shell variables.  "$#varname" will be replaced with the number of words in the value of "varname," while "$?varname" will be replaced with "1" if the variable is set, and "0" otherwise.
  106.  
  107. SHELL VARIABLE EXAMPLES
  108.  
  109. Shell variables may be set in any of the following ways:
  110.  
  111.    set a=1
  112.    set b=abc
  113.    set c
  114.       set d=()
  115.    set e=(1 2 3)
  116.       set e[1]=4
  117.  
  118. Some simple examples using the shell utility "echo" to report the results of variable substitution with the variables defined above:
  119.  
  120.    echo $a
  121.     1
  122.    echo $e
  123.     (4 2 3)
  124.    echo $e[2]
  125.     2
  126.    echo $e[$a]
  127.     4
  128.    echo Im${e[$a]}it
  129.     Im4it
  130.    echo $#e
  131.     3
  132.    echo $?b
  133.     1
  134.    echo he is $?{b}for fun
  135.      he is 1for fun
  136.    echo $?z
  137.     0
  138.  
  139. COMMAND LINE EDITING
  140.  
  141. The 'erase line' command editing function is supported in the interactive window.  This is driven by both Control-u and Command-u.  This function is actually a 'cut' operation, so the erased line may be retrieved with a paste. 
  142.  
  143. PATH AND MANPATH
  144.  
  145. MacShell supports special shell variables 'path' and 'manpath'.  
  146.  
  147. These variables should be set, preferably in the MacShell configuration file, to contain names of directories (folders) which contain compiled code resources, and executable scripts.  This will ease the process of invoking external commands and scripts, and reading associated manual entries.  
  148.  
  149. The following are sample commands which might be used to set these shell variables:
  150.    set path=(MacHD:macshell:bin: MacHD:macshell:scripts: :)
  151.    set manpath=(MacHD:macshell:bin: :)   
  152.  
  153. When a command is invoked that is not one of MacShell's built-in commands, MacShell will search the directories specified in 'path' for an appropriate executable file.  A file is considered executable by MacShell if it meets one of the following two sets of conditions:
  154. 1. Its creator tag matches MacShell's, Its type tag is 'CODE', and it contains the appropriate resource type as detailed in the information referred to in the "external code resources" section below.
  155. 2. Its creator tag matches MacShell's, its type tag is 'TEXT', and the first two characters in its data fork match the Magic Cookie (see "Scripts" below).
  156.  
  157. When a manual entry is invoked (using the "man" utility) which is not one of the built-in entries, MacShell will search the directories specified in 'manpath' for a like-named executable file.  MacShell will then attempt to locate an appropriate manual entry in the resource fork of this file.
  158.  
  159. If 'path' and/or 'manpath' are not set, the default path is the current directory (:).  If the variables are set, the current directory should normally be included explicitly.
  160.  
  161. Two commands are provided to aid in the management of path and manpath: 
  162.  
  163. 1. rehash - Rebuild internal tables associated with path and manpath.  One should use this utility after changing the contents of any directories specified therein. 
  164. 2. which - Attempt to resolve a command name using the 'path' variable, just as it would be resolved when executed by the shell.
  165.  
  166. See separate manual entries for 'rehash' and 'which' for more complete information.
  167.  
  168. ALIAS SUBSTITUTION
  169.  
  170. The alias substitution mechanism provides a simple way for the user to change the meaning of a command, or to build a new command from existing commands.  This mechanism substitutes a predefined string for the first word on a command line (or the first word on a line in a script).  It is most convenient to define aliases in one's startup file 'macshell.rc', so that they will be applied automatically to each session.
  171.  
  172. Aliases are defined by the use of the built-in command 'alias' and undefined with 'unalias'.  See separate manual entries for more details on the use of these two commands.  
  173.  
  174. If the first word on a command line is found to match a defined alias, the substitution mechanism replaces it with the list of words contained in the alias definition.  It then copys remaining arguments, from the second word of the command to the end, to the new argument list, without making any changes to them.  The new list of arguments is then passed to the variable substitutuion routine, and the file name substitution (globbing) routine, before being executed.
  175.  
  176. MacShell's alias substitution capabilities are limited in the following ways (compared to some unix shells):
  177.  
  178. - Alias substitution is not carried out recursively.
  179.  
  180. - It is not possible for an alias definition to contain arguments
  181. which are replaced at runtime.
  182.  
  183. COMMAND HISTORY
  184.  
  185. Command history is a mechanism intended to make it easier for commands invoked by means of the interactive window to be repeated.  Each command invoked is stored in a special list.  Once in the list, a command can be re-executed by means of a variety of simple keyboard shortcuts   
  186.  
  187. MacShell manages a fixed-length command history list. Items in the list are given index numbers beginning at 1.  After the list reaches its maximum length, new commands added to the list cause commands to be removed from the beginning of the list.  The numbering continues on indefinately.
  188.  
  189. The history list is currently limited to 256 elements in length.
  190.  
  191. Only commands typed to the interactive window are included in the list.  Commands invoked via shell script are ignored by the history mechanism.
  192.  
  193. The contents of the list can be examined by means of the command 'history'.  (See separate manual entry for more information).
  194.  
  195. Items in the history list can be re-executed in a variety of ways:
  196.  
  197. 1. Up-arrow and down-arrow cause the previous and next items from the history list to be pasted directly on the command line.
  198.  
  199. 2. If the special character '!' is found in a command line, the shell will attempt to parse it as a history expression of one of the below listed types, and to replace the expression with the corresponding item from the history list.  Recognized types of history expressions beginning with '!' are:
  200. a). '!!'  --  represents the previous command.
  201. b). '!n'  --  where n is an integer, represents the item in the
  202.     history list with index number n.
  203. c). '!str' -- where 'str' represents an arbitrary string, is replaced
  204.     by the most recent item in the history list beginning with the
  205.     string.
  206. This type of history substitution is carried out prior to all other forms of cammand line processing.
  207.  
  208. SCRIPTS
  209.  
  210. MacShell includes a built-in utilitiy which will open a file and execute each line as a MacShell command.  No control flow operators are supported at this time.  (For more information see the manual entry for "source").  
  211.  
  212. MacShell can also execute certain scripts  without using the "source" utility.  In order to qualify for this treatment, a script must begin with the two character sequence '#!'.  This sequence is referred to as the "Magic Cookie".  The Magic Cookie is roughly equivalent in meaning to an executable mode bit in the unix world.  
  213.  
  214. In addition, MacShell can execute certain files at launch time.  For more information, see the headings "startup files" and "configuration file" in this entry.  
  215.  
  216. STANDARD INPUT AND STANDARD OUTPUT
  217.  
  218. Standard input and output is a means by which many Unix utilities interact with the outside world.  MacShell supports this paradigm to some extent. 
  219.  
  220. Standard input may be directed to some MacShell commands from a file with the input redirection operator (<), or from the output of the preceeding command using a pipe (|).  
  221.  
  222. None of MacShell's built-in utilities use the interactive window as standard input.  However, there are now a few external code resources in existance which do.  The 'standard' character used to terminate interactive input is Control-d (and perhaps additionally Option-d).  We hope that authors of external code will observe this convention.
  223.  
  224. The default standard output for most MacShell commands is the interactive window.  If the pipe operator (|) is used, standard output is routed to the command which follows.  If the output redirection operator (>) or (>>) is present, standard output is directed to the file whose name follows the operator.
  225.  
  226.  
  227. ABOUT MACINTOSH PATH NAMES
  228.  
  229. According to Macintosh convention, the colon (:) is used in path names to separate volume, folder and file names. The following rules should be noted: 
  230.  
  231. -Absolute path names do not begin with a colon, for example:
  232.      MyDisk:MyFolder:MyFile
  233.  
  234. -When an absolute path name consists of only one name, it must end in a colon, for example:
  235.      MyDisk:
  236.  
  237. -Relative path names must begin with a colon, except in the case where they consist of only one name:
  238.      MyFolder
  239.      :MyFolder:MyFile
  240.  
  241. -Consecutive colons may be used in a path name to represent a move up the directory tree.  Two colons (::) would represent the parent of the working directory, three would represent the parent of the parent, and so on.
  242.  
  243. CASE SENSITIVITY 
  244.  
  245. The Macintosh finder and toolbox are not case sensitive.  In other words, as far as the Macintosh is concerned, "Filename" is the same as "filename."  Therefore it is not necessary to observe case when using MacShell to interface directly with the Macintosh file system.  
  246.  
  247. However, MacShell's file name substitution function IS case sensitive.  If asterisks are used as wildcard characters in file names, case must be observed in the remainder of the name (this should be changed).
  248.  
  249. NAME COMPLETION
  250.  
  251. When used interactively MacShell will attempt to complete a file name when the escape key (by default) is typed.  The user must first type enough characters to form a unique beginning of a file name.  The mechanism will add characters until a  point of ambiguity is reached, or until the file name is completed.  If the file name is not completed, the mechanism will cause a system beep.
  252.  
  253. Since Macintosh file names may include embedded spaces, and since these names must be quoted in MacShell, the name completion function will ignore a quote found at the beginning of a word.  This will allow most file names with embedded spaces to be quoted and automatically completed with ease.
  254.  
  255. The wildcard character "*" is not recognized by the file name completion mechanism.
  256.  
  257. Those using older keyboards which don't have the escape key, and those who prefer the behavior of other shells which use the tab key to trigger name completion, may alter the default behavior by setting or unsetting two special shell variables:
  258.  
  259. - Setting a variable called "remapesc" will cause the backquote key in the upper left corner of the old Mac Plus keyboard to be used to trigger name completion
  260.  
  261. - Setting a variable named "tabnc" will cause the tab key to be used to trigger the name completion mechanism.  This variable takes precedence over "remapesc" if both are set.
  262.  
  263. STARTUP FILES
  264.  
  265. MacShell treats its startup files just as most other applications do: The files are opened immediately after MacShell is launched.  However, it is also possible to cause MacShell to treat startup files as scripts to be executed.   A MacShell file will be executed on startup if the first two characters in the file are "#!".(This string is referred to as the Magic Cookie).  
  266.  
  267. Note that a file with the magic cookie will not be executed when it is opened from the File menu.
  268.  
  269. CONFIGURATION FILE
  270.  
  271. If a file called "macshell.rc" is found in the same directory with the  MacShell application, this file will be opened and executed as a script when MacShell is launched.
  272.  
  273. INVOKING EXTERNAL CODE RESOURCES FROM MACSHELL
  274.  
  275. It's possible to write code in a language like C or Pascal, and compile it into code resources which can be called directly by MacShell. Sample code (in C) demonstrating how to do this is available.  This information is currently available via anonymous ftp from:
  276.    ftp.cs.washington.edu:/homes/fred/externalCode.sit.Hqx
  277. or from the MacShell web page (see below).
  278.  
  279. KNOWN INCOMPATIBILITIES
  280.  
  281. It was reported to the author that an extension named 'TypeIt4Me' caused MacShell's 'cd' command to operate incorrectly.
  282.  
  283. MACSHELL SOURCE CODE
  284.  
  285. Full MacShell source code is also available from:
  286.    ftp.cs.washington.edu:/homes/fred/MacShell.X.XXx.src.sit
  287. or from the MacShell web page (see below).
  288.  
  289. If you do any generally useful work with this source (modifications, extensions, bug fixes), I would be interested in receiving your patches for possible inclusion in future (free) versions of MacShell.
  290.  
  291. MACSHELL WEB PAGE
  292.  
  293. A page of information about MacShell, including pointers to the latest executable, source, and code resource packages is available at:
  294.    http://www.cs.washington.edu/homes/fred/macshell.html
  295.  
  296. CREDITS
  297.  
  298. Thanks to the following for their contributions:
  299.  
  300. Adolfo Villafiorita did lots of work on the external code resource template, and wrote several great external commands.
  301.  
  302. Greg Dunn ported the source to ThinkC 7.0 and colorized the icons.
  303.  
  304. HOW TO CONTACT THE AUTHOR
  305.  
  306. By email:
  307.    fred@cs.washington.edu
  308.  
  309.  
  310.